package vn.vnvas.xoso.utils;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;


public class WebService {
	private final String SOAP_ADDRESS = "http://115.84.179.72/wsxoso/Service.asmx";
	
	public String WsGETNGAYMIENBAC(String method_name) {
		final String SOAP_ACTION = "http://tempuri.org/" + method_name;
		final String METHOD_NAME = method_name;
		final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, METHOD_NAME);		

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call(SOAP_ACTION, envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}
	
	public String WsGETNGAYTRUNGNAM(String method_name, String pi_name,
			int pi_value) {
		final String SOAP_ACTION = "http://tempuri.org/" + method_name;
		final String METHOD_NAME = method_name;
		final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, METHOD_NAME);

		//push data to server
		PropertyInfo pi = new PropertyInfo();
		pi.setName(pi_name);
		pi.setValue(pi_value);
		pi.setType(Integer.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call(SOAP_ACTION, envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}
	
	

	public String WsXoSo(String method_name, String pi_name,
			String pi_value) {
		final String SOAP_ACTION = "http://tempuri.org/" + method_name;
		final String METHOD_NAME = method_name;
		final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, METHOD_NAME);

		//push data to server
		PropertyInfo pi = new PropertyInfo();
		pi.setName(pi_name);
		pi.setValue(pi_value);
		pi.setType(Integer.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call(SOAP_ACTION, envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}
	
	public String WsXoSoMB(String method_name, String pi_name, int pi_value,String pi_name2,int pi_value2) {
		final String SOAP_ACTION = "http://tempuri.org/" + method_name;
		final String METHOD_NAME = method_name;
		final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, METHOD_NAME);

				
		request.addProperty(pi_name,pi_value);
		request.addProperty(pi_name2,pi_value2);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call(SOAP_ACTION, envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}
	
	public String WsXoSoTrungNam(String method_name, String pi_name, int pi_value,String pi_name2,int pi_value2, String pi_name3, int pi_value3) {
		final String SOAP_ACTION = "http://tempuri.org/" + method_name;
		final String METHOD_NAME = method_name;
		final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, METHOD_NAME);

				
		request.addProperty(pi_name,pi_value);
		request.addProperty(pi_name2,pi_value2);
		request.addProperty(pi_name3,pi_value3);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call(SOAP_ACTION, envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}
	
	public String WsTimKetQuaMienBac(String method_name, String pi_name, String pi_value) {
		final String SOAP_ACTION = "http://tempuri.org/" + method_name;
		final String METHOD_NAME = method_name;
		final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, METHOD_NAME);

				
		request.addProperty(pi_name,pi_value);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call(SOAP_ACTION, envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}
	
	public String WsTimKetQuaTrungNam(String method_name, String pi_name, int pi_value,String pi_name2, String pi_value2) {
		final String SOAP_ACTION = "http://tempuri.org/" + method_name;
		final String METHOD_NAME = method_name;
		final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, METHOD_NAME);

				
		request.addProperty(pi_name,pi_value);
		request.addProperty(pi_name2,pi_value2);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call(SOAP_ACTION, envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}
	
}